package espace_logique;

import espace_logique.*;
import fichiers.Dossier;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.tree.*;
import support.*;


public class VueAjoutAlbum extends JDialog{
   
    
    private JLabel lNom;
    private JTextField tNom;
    private JButton ok,annuler;
    private JTree arbre;
    /** Creates a new instance of VueAjoutAlbum */
    public VueAjoutAlbum(JTree arbre,JFrame parent) {
        super(parent,"Album Propriétés",true);
        
        this.arbre=arbre;
        lNom = new JLabel("Nom: ");
        ok = new JButton("Ok");
        annuler = new JButton("Annuler");
        tNom = new JTextField(20);
        ok.addActionListener(new ActionAdd());
        annuler.addActionListener(new ActionAnnuler());
        
        this.setSize(300,100);
        this.setResizable(false);
        this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        Container contenu=this.getContentPane();
        contenu.setLayout(new BorderLayout());
        JPanel pancentral = new JPanel();
        pancentral.setLayout(new FlowLayout());
        pancentral.add(lNom);
        pancentral.add(tNom);
        pancentral.add(ok,BorderLayout.EAST);
        pancentral.add(annuler,BorderLayout.SOUTH);
        add(pancentral);
        this.setVisible(true);
        
        
    }
    

    
    public class ActionAdd implements ActionListener{
        public void actionPerformed(ActionEvent e){
            
            Dossier el=(Dossier)((DefaultMutableTreeNode)arbre.getSelectionPath().getLastPathComponent()).getUserObject();
            Dossier d=new Dossier(el,el.getFichierCourant(),tNom.getText());
            el.ajouterSousElement(d,el.getIndex(d));
            setVisible(false);
        }
    }
    
    public class ActionAnnuler implements ActionListener{
        public void actionPerformed(ActionEvent e){
            setVisible(false);
        }
    }
    
}

